package com.ruoyi.vote.admin.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.vote.admin.service.IWxSubTampService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.vote.admin.domain.vo.WxSubTampVo;
import com.ruoyi.vote.admin.domain.bo.WxSubTampBo;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信订阅消息模板
 *
 * @author 筑巢
 * @date 2023-07-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/weixin/subTamp")
public class WxSubTampController extends BaseController {

    private final IWxSubTampService iWxSubTampService;

    /**
     * 查询微信订阅消息模板列表
     */
    @SaCheckPermission("weixin:subTamp:list")
    @GetMapping("/list")
    public TableDataInfo<WxSubTampVo> list(WxSubTampBo bo, PageQuery pageQuery) {
        return iWxSubTampService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出微信订阅消息模板列表
     */
    @SaCheckPermission("weixin:subTamp:export")
    @Log(title = "微信订阅消息模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WxSubTampBo bo, HttpServletResponse response) {
        List<WxSubTampVo> list = iWxSubTampService.queryList(bo);
        ExcelUtil.exportExcel(list, "微信订阅消息模板", WxSubTampVo.class, response);
    }

    /**
     * 获取微信订阅消息模板详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("weixin:subTamp:query")
    @GetMapping("/{id}")
    public R<WxSubTampVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iWxSubTampService.queryById(id));
    }

    /**
     * 新增微信订阅消息模板
     */
    @SaCheckPermission("weixin:subTamp:add")
    @Log(title = "微信订阅消息模板", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxSubTampBo bo) {
        return toAjax(iWxSubTampService.insertByBo(bo));
    }

    /**
     * 修改微信订阅消息模板
     */
    @SaCheckPermission("weixin:subTamp:edit")
    @Log(title = "微信订阅消息模板", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WxSubTampBo bo) {
        return toAjax(iWxSubTampService.updateByBo(bo));
    }

    /**
     * 删除微信订阅消息模板
     *
     * @param ids 主键串
     */
    @SaCheckPermission("weixin:subTamp:remove")
    @Log(title = "微信订阅消息模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWxSubTampService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
